from flask import Flask, jsonify, request, send_file, render_template
from flask_cors import CORS
import requests
import json

app = Flask(import_name = __name__, static_folder='static')
CORS(app, supports_credentials=True)

@app.route("/login",methods=['POST'])
def login():
    print(request.args.get('name'))
    name = request.args.get('name')
    password = request.args.get('password')
    
    if(name=='admin'and password=='admin'):
        return jsonify('success')
    else:
        return('false')

@app.route("/control",methods=["GET"])
def control():
    x = requests.get('http://39.106.79.148:7000/Administrator/getHome')
    data = json.loads(x.text)
    print(data)
    return jsonify(data)

@app.route('/examine',methods=['POST'])
def examine():
    name = request.args.get('homeName')
    print(name)
    url = 'http://39.106.79.148:7000/Administrator/Verify?homeName='+name+'&verifyCode=审核通过'
    req = requests.post(url)
    return jsonify('success')

@app.route('/update',methods=['POST'])
def update():
    name = request.args.get('homeName')
    print(name)
    url = 'http://39.106.79.148:7000/Administrator/Verify?homeName='+name+'&verifyCode=审核不通过'
    req = requests.post(url)
    return jsonify('success')
    
@app.route('/home')
def home():
    return render_template('home.html')
    # return send_file('home.html')

@app.route('/loginPage')
def loginPage():
    return render_template('login.html')
    # return send_file('login.html')

@app.route('/failedPage')
def failedPage():
    return render_template('index.html')
    # return send_file('index.html')

@app.route('/controlPage')
def controlPage():
    return render_template('control.html')
    # return send_file('control.html')
    
if __name__ == '__main__':
    app.run(host='0.0.0.0',port='5000')
